package com.mk.admin.controller;

import com.mk.admin.log.WriteLog;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.query.PatientCardHeathCardQuery;
import com.mk.admin.model.query.PatientSelectQuery;
import com.mk.admin.model.vo.*;
import com.mk.admin.service.PatientCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/a/adm/patientCard")
@Api(tags = "患者管理")
public class PatientCardController {
    @Autowired
    private PatientCardService patientCardService;

    @PostMapping("/select")
    @WriteLog("患者管理查询")
    @ApiOperation("患者管理查询")
    public ResultDto select(@RequestBody PatientCardVo vo) {
        return patientCardService.select(vo);
    }

    @PostMapping("/changeCard")
    @ApiOperation(value = "切换就诊卡", tags = "就诊卡", notes = "将彼此的loginStatus互换")
    public ResultDto changeCard(@RequestBody PatientCardChangeVo vo) {
        return patientCardService.changeCard(vo);
    }

    @PostMapping("/patientSelect")
    @ApiOperation(value = "opt_0001门诊患者查询,", tags = "就诊卡", notes = "建档时，查询远程是否有患者，如果有，则继续查询本地数据是否有，如果本地没有，则新增，如果本地有，则修改")
    public ResultDto patientSelect(@RequestBody PatientSelectQuery query) {
        return patientCardService.patientSelect(query);
    }

    @PostMapping("/add")
    @WriteLog("患者管理新增")
    @ApiOperation("患者管理新增")
    public ResultDto add(@RequestBody PatientCardVo vo) {
        return patientCardService.add(vo);
    }

    @PostMapping("/record")
    @ApiOperation(value = "opt_0020首诊患者建档", tags = "就诊卡", notes = "平台通过通过本接口传送用户的实名认证信息，为首诊用户建档(自助机建卡需传入就诊卡号，微信、app传入卡号可为空,当前卡号为空时，HIS将生成一个虚拟就诊卡号)")
    public ResultDto record(@RequestBody PatientCardRecordVo vo) {
        return ResultDto.data(patientCardService.record(vo));
    }

    @PostMapping("/update")
    @WriteLog("患者管理修改")
    @ApiOperation("患者管理修改")
    public ResultDto update(@RequestBody PatientCardVo vo) {
        return patientCardService.update(vo);
    }

    @PostMapping("/updateCampus")
    @WriteLog("患者管理修改院区")
    @ApiOperation("患者管理修改院区")
    public ResultDto updateCampus(@RequestBody PatientCardVo vo) {
        return patientCardService.updateCampus(vo);
    }

    @PostMapping("/updateHealthInfo")
    @WriteLog("患者管理修改健康档案")
    @ApiOperation("患者管理修改健康档案")
    public ResultDto updateHealthInfo(@RequestBody PatientCardVo vo) {
        return patientCardService.updateHealthInfo(vo);
    }

    @PostMapping("/delete")
    @WriteLog("患者管理删除")
    @ApiOperation("患者管理删除")
    public ResultDto delete(@RequestBody PatientCardVo vo) {
        return patientCardService.delete(vo.getId());
    }

    @PostMapping("/status")
    @WriteLog("患者管理状态")
    @ApiOperation("患者管理状态")
    public ResultDto status(@RequestBody PatientCardVo vo) {
        return patientCardService.status(vo.getId());
    }

    @PostMapping("/loginStatus")
    @WriteLog("患者管理登录状态")
    @ApiOperation(value = "患者管理登录状态", notes = "只更改登录状态1为登录，0为未登录")
    public ResultDto loginStatus(@RequestBody PatientCardVo vo) {
        return patientCardService.loginStatus(vo.getLoginStatus());
    }

    @PostMapping("/healthCardList")
    @ApiOperation(value = "电子健康卡查询", tags = "就诊卡", notes = "查询卫建委健康卡")
    public ResultDto healthCardList(@RequestBody PatientCardHeathCardQuery query) {
        return patientCardService.healthCardList(query);
    }

    @PostMapping("/addHealthCard")
    @ApiOperation(value = "ehc_1001新增电子健康卡", tags = "就诊卡", notes = "新增电子健康卡")
    public ResultDto addHealthCard(@RequestBody PatientCardAddHeathCardVo vo) {
        return patientCardService.addHealthCard(vo);
    }

    @ApiOperation("微信code码")//ok
    @GetMapping("/weChatCode")
    public ResultDto weChatCode(@RequestParam("code") String code) {
        return patientCardService.weChatCode(code);
    }
}
